package thread.notifydemo;

import java.util.concurrent.atomic.AtomicInteger;

public class WhileDemo {
    public static Object object = new Object();
    static AtomicInteger value = new AtomicInteger(1);
    static int num =0;


    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (object) {
                while (true) {
                    System.out.println("==");
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                    }
                    System.out.println("++");
                }
            }
        }, "A").start();
    }


    public void add(){
        synchronized (object){
            while (num!=0){
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            num++;
            System.out.println(Thread.currentThread().getName()+"\r"+num);
            object.notify();
        }

    }
}
